<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/styleold.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">登录</div>
    </header>
    <div class="aui-bar-nav-d"></div>

    <div class="login">
        <img src="image/logo.png">
        <ul class="user-password">
            <li>
                <label>账号</label>
                <input class="text-1" type="text" placeholder="请输入您的手机号码/用户名" id="mobile">
                <div class="check" id="checkPhone"></div>
            </li>
            <li>
                <label>密码</label>
                <input class="text-1" type="password" placeholder="请输入密码" id="PWD">
                <div class="check" id="checkPSW"></div>
            </li>
        </ul>
        <p tapmode onclick="user_mobile_verification()">忘记密码</p>
    </div>

    <div class="user-data-btn" tapmode onclick="login()">登录</div>

    <div class="login-d">
        <a tapmode onclick="register()">注册账号</a>
    </div>

    <div class="licai-buy-box-bg">
        <div class="licai-buy-box">
            <h3>请设置交易密码</h3>
            <input type="password" name='new_pwd' placeholder="请设置交易密码">
            <input type="password" name='new_pwd2' placeholder="确认交易密码">
            <div class="licai-buy-box-btn">
                <a class="green" onclick="licai_box_password()">确定</a>
                <a class="green" onclick="licai_box_close()">取消</a>
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    apiready = function() {
        //腾讯统计

    }

    function licai_box_password() {

        var userid = $api.getStorage('userid');
        var new_pwd = $(" input[ name='new_pwd' ] ").val();
        var new_pwd2 = $(" input[ name='new_pwd2' ] ").val();
        api.ajax({

            url: webAddress + '/index.php?ctl=app_user_center2&act=set_paypassword',
            method: 'post',
            data: {
                values: {
                    id: userid,
                    new_pwd: new_pwd,
                    new_pwd2: new_pwd2,
                },
            }
        }, function(ret, err) {
            if (ret.status == 1) {
                $api.setStorage('payPassWord', new_pwd2);
                api.toast({
                    msg: ret.info,
                    duration: 2000,
                    location: 'bottom'
                });
                setTimeout("lock()", 500);

            } else {
                api.toast({
                    msg: ret.info,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
    }



    function licai_box_close() {
        $(".licai-buy-box-bg").hide();
    }

    // 登录
    function login() {
        // 登录手机号码/用户名
        var mobile = $api.byId('mobile');
        var mobileValue = mobile.value;
        lastMobileValue = mobileValue;

        // 手机号不能为空
        if (!mobileValue) {
            $api.byId('checkPhone').innerText = '手机号不能为空';
            return false;
        } else {
            $api.byId('checkPhone').innerText = '';
        }

        // apns_code
        var deviceId = api.deviceId;
        // 登录密码
        var PWD = $api.byId('PWD');
        var PWDValue = PWD.value;
        // 密码不能为空
        if (!PWDValue) {
            $api.byId('checkPSW').innerText = '密码不能为空';
            return false;
        } else {
            $api.byId('checkPSW').innerText = '';
        }
        var funName = 'updateData();';
        api.ajax({
            url: webAddress + '/index.php?ctl=app_user_center&act=mobiledologin&ajax=1',
            method: 'post',
            data: {
                values: {
                    mobile: mobileValue,
                    user_pwd: PWDValue,
                    apns_code: deviceId
                },
            }
        }, function(ret, err) {
            if (ret) {
                // console.log(JSON.stringify(ret));
                if (ret.status == 0) {
                    api.toast({
                        msg: ret.info,
                        duration: 2000,
                        location: 'bottom'
                    });

                    PWD.focus();
                    return false;
                } else {
                    var rett = ret;
                    var userid = rett.user.id;
                    $api.setStorage('userid', userid);
                    $api.setStorage('mobile', mobileValue);
                    $api.setStorage('is_gesture', null);

                    var gesture = rett.user.gesture;
                    var paypassword = rett.user.paypassword;
                    $api.setStorage('gesture', gesture);

                    var registrationId = $api.getStorage('registrationId');
                    api.ajax({
                        url: webAddress + '/index.php?ctl=app_user_center2&act=set_apns_code',
                        method: 'post',
                        data: {
                            values: {
                                apns_code: registrationId,
                                id: userid
                            }
                        }
                    }, function(ret, err) {
                        if (gesture == '' && paypassword == '') {
                            api.openWin({
                                name: 'h5Lock',
                                url: './h5Lock.html',
                                pageParam: {
                                    name: 'login'
                                }
                            });
                        } else {

                            followLogin();
                        }

                    });

                }
            } else {
                alert(err.msg);
            }
        });
    }


    // 登录成功之后,安卓系统后续处理
    function followLogin() {
        // 已经添加手势
        showToast();

        // 判断哪一页登录的参数
        var param = api.pageParam.login;
        var id = api.pageParam.id;
        if (param == 'syx_buy') {
            sendMsg();
            // 上页面刷新数据
            var refreshData = 'load_list(id);';
            api.execScript({
                name: 'syx_buy',
                script: refreshData,
            });

            // 成功后关闭登录页面
            api.closeToWin({
                name: 'syx_buy'
            });
        } else if (param == 'znlc_buy') {
            sendMsg();
            // 上页面刷新数据
            var refreshData = 'load_list(id);';
            api.execScript({
                name: 'znlc_buy',
                script: refreshData,
            });

            // 成功后关闭登录页面
            api.closeToWin({
                name: 'znlc_buy'
            });
        } else if (param == 'claims_details') {
            sendMsg();
            // 上页面刷新数据
            var refreshData = 'load_list(id);';
            var refreshData2 = 'load_list2(id);';
            api.execScript({
                name: 'claims_details',
                script: refreshData,
            });
            api.execScript({
                name: 'claims_details',
                script: refreshData,
            });

            // 成功后关闭登录页面
            api.closeToWin({
                name: 'claims_details'
            });

        } else {
            var setSele = 'randomSwitchBtn(2);';
            api.execScript({
                name: 'root',
                script: setSele,
            });
            api.execScript({
                name: 'root',
                script: 'registerjkPush()',
            });


            api.closeToWin({
                name: 'root'
            });
        }

    };

    // 登录成功toast提示框
    function showToast() {
        api.toast({
            msg: '登录成功',
            duration: 2000,
            location: 'middle'
        });

    }

    // open注册
    function register() {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'register',
            url: './register.html',
            pageParam: {
                name: 'test'
            }
        });
    }

    // open忘记密码
    function user_mobile_verification() {
        api.openWin({
            name: 'user_mobile_verification-pwd',
            url: './user_mobile_verification.html',
            pageParam: {
                name: 'test'
            }
        });
    }

    // 登录成功发送刷新请求
    function sendMsg() {
        api.sendEvent({
            name: 'login_success',
            extra: {
                key1: 'value1',
                key2: 'value2'
            }
        });
    }

    // 注册
    function register() {
        var delay = 0;
        if (api.systemType != 'ios') {
            // delay = 300;
        }
        api.openWin({
            name: 'register',
            url: './register.html',
            bounces: false,
            delay: delay,
            slidBackEnabled: true,
            vScrollBarEnabled: false,
            progress: {
                type: "page"
            }
        });
    };





    // 修改密码之后,登录页面自动补充手机号
    function setMobile() {
        var mobile = $api.getStorage('mobile');
        // alert(mobile);
        if (mobile) {
            var mobileEle = $api.byId('mobile');
            mobileEle.value = mobile;
        }
    }

    // function user_mobile_verification(){
    //     var delay = 0;
    //     if(api.systemType != 'ios'){
    //         // delay = 300;
    //     }
    //     api.openWin({
    //         name: 'user_mobile_verification',
    //         url: './user_mobile_verification.html',
    //         bounces:false,
    //         delay: delay,
    //         slidBackEnabled:true,
    //         vScrollBarEnabled:false,
    //         progress:{
    //             type:"page"
    //         }
    //     });
    // };
    function closeWin() {

        api.closeWin({});
    }
</script>

</html>
